package com.tzbank.wisdom.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.tzbank.esb.util.EsbConsumerUtil;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultCode;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.service.CreditService;
import com.tzbank.wisdom.utils.RequestMap;
import com.tzbank.wisdom.utils.TransCodeEnum;

@Service(value = "CreditService")
public class CreditServiceImpl implements CreditService {

    /**
     * 贷记卡自动还款协议签约
     */
    @Override
    public Map<String, Object> creditAutoPaySign(Map<String, String> reqBody) {
        // 组装入参Map
        Map<String, Object> inputMap = new HashMap<String, Object>();
        //调用核心计价因子报文头入参
        Map<String, Object> reqSysHead1 = RequestMap.getReqSysHead(TransCodeEnum.TRANS_CREDITAUTOPAYSIGN.getServiceCode(), TransCodeEnum.TRANS_CREDITAUTOPAYSIGN.getServiceSence(), "", "0110", "");
        //调用核心计价因子入参
        inputMap.put("sysHead", reqSysHead1);
        inputMap.put("creditCardNo", reqBody.get("creditCardNo"));//信用卡账户6223218000024105
        inputMap.put("payerAcctNo", reqBody.get("payerAcctNo"));//还款账户6224271190345698-103
        inputMap.put("acctName", reqBody.get("acctName"));//账户姓名张扬
        inputMap.put("repayType", reqBody.get("repayType"));//还款类型T
        inputMap.put("creidtAmt", reqBody.get("creidtAmt"));//信用卡额度
        inputMap.put("tranPassword", reqBody.get("tranPassword"));//交易密码48E01531CFA59624
        Map<String, Object> result = EsbConsumerUtil.clientRequest(inputMap); // 贷记卡自动还款协议签约结果
        if (!CodeUtil.CODE_200.getCode().equals(result.get("code"))) {
            return ResultUtil.resultMap(result.get("msg").toString(), ResultCode.RESUTL_CODE_FAILURE.code(),
                    result.get("data"));
        }
        Map<String, Object> dataMap = (Map<String, Object>) result.get("data");
        dataMap.remove("head");
        result.put("data", dataMap);
        return ResultUtil.resultMap(ResultCode.RESULT_CODE_SUCCESS.desc(), ResultCode.RESULT_CODE_SUCCESS.code(), result.get("data"));

    }
}